package org.example.smartbuy.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.smartbuy.entity.Reviews;
import org.example.smartbuy.mapper.ReviewsMapper;
import org.example.smartbuy.service.IReviewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Smarty Buy
 * @since 2024-11-18
 */
@Service
public class ReviewsServiceImpl extends ServiceImpl<ReviewsMapper, Reviews> implements IReviewsService {

    @Autowired
    private ReviewsMapper reviewsMapper;

    @Override
    public List<Reviews> listById(int id) {
        QueryWrapper<Reviews> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id", id);
        return reviewsMapper.selectList(queryWrapper);
    }

    @Override
    public Reviews getById(int id) {
        return reviewsMapper.selectById(id);
    }

    @Override
    public Reviews add(Reviews reviews) {
        reviewsMapper.insert(reviews);
        return reviews;
    }

    @Override
    public void delete(int id) {
        reviewsMapper.deleteById(id);
    }
}
